package cn.iocoder.springboot.lab03.kafkademo.controller;

import cn.iocoder.springboot.lab03.kafkademo.anotation.Secured;
import cn.iocoder.springboot.lab03.kafkademo.crane.Schedule;
import cn.iocoder.springboot.lab03.kafkademo.entity.Po.Item;
import cn.iocoder.springboot.lab03.kafkademo.entity.SignType;
import cn.iocoder.springboot.lab03.kafkademo.enums.ActionTypes;
import cn.iocoder.springboot.lab03.kafkademo.producer.Demo08Producer;
import cn.iocoder.springboot.lab03.kafkademo.service.PositionServiceImpl;
import cn.iocoder.springboot.lab03.kafkademo.service.RedisOptService;
import cn.iocoder.springboot.lab03.kafkademo.utils.StringUtils;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.ExecutionException;

/**
 * @Author：YH
 * @Description：
 * @Date:Created in 2022/1/3 1:45
 */
@RestController
@Slf4j
public class ControllerTest {

    @Autowired
    Demo08Producer demo08Producer;
    @Resource
    private ApplicationContext applicationContext;
    @Resource
    private PositionServiceImpl positionService;
    @Resource
    private RedisOptService redisOptService;
    @Resource
    private Schedule schedule;

    @PostMapping(value = "/publishConfig")
    @Secured(action = ActionTypes.WRITE, signType = SignType.CONFIG)
    public Boolean publishConfig(HttpServletRequest request, @RequestParam(value = "dataId") String dataId,
                                 @RequestParam(value = "group") String group,
                                 @RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant,
                                 @RequestParam(value = "content") String content, @RequestParam(value = "tag",
            required = false) String tag,
                                 @RequestParam(value = "appName", required = false) String appName,
                                 @RequestParam(value = "src_user", required = false) String srcUser,
                                 @RequestParam(value = "config_tags", required = false) String configTags,
                                 @RequestParam(value = "desc", required = false) String desc,
                                 @RequestParam(value = "use", required = false) String use,
                                 @RequestParam(value = "effect", required = false) String effect,
                                 @RequestParam(value = "type", required = false) String type,
                                 @RequestParam(value = "schema", required = false) String schema) {
        return false;

    }

    @GetMapping(value = "/test")
    @ResponseBody
    public String createOrderTest(@RequestParam("id") Integer id) throws ExecutionException, InterruptedException {
        //redisOptService.zset();
        //return "";

        for (int i = 0; i < 50; i++) {
            for (int j = 0; j < 300; j++) {
                Item intermFromCacheAndDb = schedule.getIntermFromCacheAndDb(j);
            }
        }

        Item intermFromCacheAndDb = schedule.getIntermFromCacheAndDb(id);
        return JSON.toJSONString(intermFromCacheAndDb);
    }
}
